using Framework;

public struct StringDef
{
    public static ByteBuffer Buffer;
    private string _value;
    private int _offset;
    public string Value
    {
        get
        {
            if (_value != null)
            {
                return _value;
            }
            if (_offset > 0)
            {
                var count = Buffer.ReadUshort(_offset);
                _value = Buffer.ReadStringUTF8(_offset + 2, count);
                return _value;
            }
            _value = string.Empty;
            return _value;
        }
    }
    public StringDef(string value, int offset = 0)
    {
        _value = value;
        _offset = offset;
    }
    public StringDef(ByteArray buffer)
    {
        _value = null;
        _offset = buffer.Position;
        var count = buffer.ReadUshort();
        var pos = buffer.Position;
        buffer.SetPosition(pos + count);
    }
}